package cn.mw.cmdb.config.MQTT;

import cn.mw.microMonitorCommon.util.RedisUtils;
import cn.mw.microMonitorCommon.util.SpringUtils;
import org.apache.commons.collections4.CollectionUtils;

import java.util.HashSet;
import java.util.Set;

public interface MessageArrivedHandle {
    public static final String LabelStateKey = "/LabelState";
    public static final String UMonitorModelIdKey = "UMonitorModelId";
    public static final String onlineStatePath = "data.onlineState";
    public static final String onlineStateKey = "onlineState";

    public static final String redisUMangeKey = "heartBeatStateUNumManage::";
    //U位预占用指示灯
    public static final int UIndexReservedUsedState = 13;
    //U位预释放指示灯
    public static final int UIndexReservedFreeState = 13;
    //U位空闲指示灯
    public static final int UIndexFreeState = 0;
    //U位占用正确指示灯
    public static final int UIndexUsedOKState = 4;
    //U位占用错误指示灯(非法占用，非法下架)
    public static final int UIndexUsedFailState = 8;


    void messageManage(String topic, Object message) throws Exception;

    default public void setRedisUMangeKey(String gatewayId, Set<String> moduleSnList) {
        String key = redisUMangeKey + gatewayId;
        if (CollectionUtils.isNotEmpty(moduleSnList)) {
            RedisUtils redisUtil = SpringUtils.getBean(RedisUtils.class);
            Object dataInfo = redisUtil.get(key);
            Set dataInfoSet = new HashSet();
            if (dataInfo != null && dataInfo instanceof Set<?>) {
                moduleSnList.addAll((Set) dataInfo);
                dataInfoSet = moduleSnList;
            } else {
                dataInfoSet = moduleSnList;
            }
            redisUtil.set(key, dataInfoSet, 200);
        }
    }
}
